package com.cn.aam.checaiduo.base.web;

import android.content.Context;
import android.webkit.WebView;

import com.cn.aam.checaiduo.AppData;
import com.cn.aam.checaiduo.base.BaseActivity;
import com.cn.aam.checaiduo.center.CustomDialogCenter;
import com.cn.aam.checaiduo.ui.me.ReservationListActivity;

import static com.cn.aam.checaiduo.base.web.WebViewHelper.GOTO.MEFRAGMENT;
import static com.cn.aam.checaiduo.base.web.WebViewHelper.GOTO.OTHER;

/**
 * monker on 2017/6/13.
 */

public class WebViewHelper {

    public enum GOTO {
        MEFRAGMENT, OTHER
    }


    public GOTO shouldGoToFlag = OTHER;

    public static WebViewHelper getInstance() {
        return WebViewHelperHolder.INTANCE;
    }

    static class WebViewHelperHolder {
        private static final WebViewHelper INTANCE = new WebViewHelper();
    }

    /**
     * 时间：2017/6/13
     * 描述：url事件分发
     */
    public void dispatchUrl(String url, WebView view) {
        Context context = AppData.currentActivity();
        if (url.contains("Usercenter/finance")) {//新浪充值成功后，跳转到理财中心页面
            if (shouldGoToFlag == MEFRAGMENT) {
                AppData.closeActivityExceptMain();
            }
        }
        if (url.contains("Usercenter/index")) {//用户实名验证成功后，弹出弹窗
            CustomDialogCenter.getInstance().showAuthSuccessDialog(context);

        }
        if (url.contains("Wap/Finance/autoTender")) {//自动预约成功或者失败之后
            context.startActivity(ReservationListActivity.newInstance(context));
            ((BaseActivity) context).onBackPressed();
        }
        shouldGoToFlag = OTHER;//执行之后，清除标志
    }

    public WebViewHelper setGotoFlag(GOTO flag) {
        shouldGoToFlag = flag;
        return this;
    }
}
